package com.etrans.web.gps.business.system.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.system.domain.QuestionVO;

@Service
public class QuestionService extends BaseService {

	public List<QuestionVO> queryAllQuestions(HashMap<String, Object> params) {
		return this.selectList("questionQuery.queryAllQuestions", params);
	}

	public long allQuestionsCount(HashMap<String, Object> params) {
		return (Long) this.selectOne("questionQuery.allQuestionsCount", params);
	}
	
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,Exception.class })
	public int saveQuestion(QuestionVO question) {
		this.insert("questionMapper.saveQuestion", question);
		return question.getId();
	}
	
	public int deleteQuestion(int questionId) {
		return this.delete("questionMapper.deleteQuestion", questionId);
	}

	public long checkQuestionName(String question) {
		HashMap<String, Object> params = new HashMap<>();
		params.put("question", question);
		return (Long) this.selectOne("questionQuery.checkQuestionName", params);
	}
	
	public long findStrategyByQuestionId(Integer questionId) {
		HashMap<String, Object> params = new HashMap<>();
		params.put("questionId", questionId);
		return (Long) this.selectOne("questionQuery.findStrategyByQuestionId", params);
	}
	
	
}
